package com.prestamomo.vil.ppa.pmvilmedium.pmvilarm;

import static android.os.BatteryManager.BATTERY_STATUS_UNKNOWN;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class PmvilCellReverMd extends BroadcastReceiver {
    public static JSONObject pmvilCellJsbon = null;

    private Map<String, Object> pmvilreslMp = new HashMap<>();
    @Override
    public void onReceive(Context context, Intent intent) {
        switch (intent.getAction()) {
            case Intent.ACTION_BATTERY_CHANGED:
                pmvilreslMp.put("pmvilsei",true);
                if (pmvilCellJsbon == null) pmvilCellJsbon = new JSONObject();
                try {
                    pmvilreslMp.put("pmvilseisew","jpmwos");
                    pmvilCellJsbon.put("doktfjyvm", intent.getIntExtra("xzfoua", 0));//battery_pct
                    int plugged_status = intent.getIntExtra("plugged", 0);
                    pmvilCellJsbon.put("ealsshp", plugged_status == 2 ? 1 : -1);//is_usb_charge
                    pmvilCellJsbon.put("pymix", plugged_status == 1 ? 1 : -1);//is_ac_charge
                    int status = intent.getIntExtra("status", BATTERY_STATUS_UNKNOWN);
                    if (status == 2) {
                        pmvilCellJsbon.put("jvsha", 1);//is_charging
                    } else {
                        pmvilCellJsbon.put("jvsha", -1);//is_charging
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    pmvilreslMp.put("pmvilsei",false);
                    pmvilreslMp.put("pmvilseisew","likw");
                }finally {
                    if (pmvilreslMp.size()!=0) pmvilreslMp.clear();
                }
                break;
        }
    }

    public static JSONObject getBatterJson() {
        return pmvilCellJsbon;
    }
}
